package com.weijianhuawen.wjblog.admin.controller;

import com.weijianhuawen.wjblog.admin.mode.vo.tag.*;
import com.weijianhuawen.wjblog.admin.service.AdminTagService;
import com.weijianhuawen.wjblog.common.aspect.ApiOperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @version: java version 8
 * @Author: weijianhuawen
 * @description: 标签controller
 * @date: 2024-10-22 16:48
 */
@RestController
@RequestMapping("/admin")
@Api(tags = "Admin 标签模块")
public class AdminTagController {

    @Autowired
    private AdminTagService adminTagService;


    //新增标签
    @PostMapping("/tag/add")
    @ApiOperation(value = "新增标签")
    @ApiOperationLog(description = "新增标签")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Object addTag(@RequestBody @Validated AddTagReqVo vo) {
        return adminTagService.addTag(vo);
    }

    @PostMapping("/tag/list")
    @ApiOperation(value = "分页查询标签列表")
    @ApiOperationLog(description = "分页查询标签列表")
    public Object findTagList(@RequestBody @Validated FindTagPageListReqVo vo) {
        return adminTagService.findTagList(vo);
    }

    @PostMapping("/tag/delete")
    @ApiOperation(value = "通过id删除标签")
    @ApiOperationLog(description = "根据传入的id删除标签")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Object deleteCategory(@RequestBody @Validated DeleteTagReqVo vo) {
        return adminTagService.deleteTag(vo);
    }

    @PostMapping("/tag/search/like")
    @ApiOperation(value = "模糊查询标签")
    @ApiOperationLog(description = "模糊查询标签")
    public Object searchLikeTag(@RequestBody @Validated SearchLikeTagReqVo vo) {
        return adminTagService.searchLikeTag(vo);
    }

    @PostMapping("/tag/add/one")
    @ApiOperation(value = "添加单个标签")
    @ApiOperationLog(description = "添加单个标签")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Object addOneCategory(@RequestBody @Validated AddOneTagReqVo vo) {
        return adminTagService.addOneCategory(vo);
    }

    @GetMapping("/tag/select/list")
    @ApiOperation(value = "查询标签 Select 列表数据")
    @ApiOperationLog(description = "查询标签 Select 列表数据")
    public Object findTagSelectList() {
        return adminTagService.findTagList();
    }
}
